*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** Figure A6
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~		
	
use data/processed/data_1, clear 
keep if control_pure==1 |control_fincrisis==1 | control_dotcom==1 | control_black==1 

	*~ constrained
	gen h_constrained=(constrained>3)
	gen h_retired = (retired==1)

	*~ age 
	gen h_age=(age>48)
	tab hhnetinc_19 if hhnetinc19_NR==0

	*~ net income 
	gen h_netinc=(hhnetinc_19>4)
	gen h_netinc_alt=(hhnetinc_19>3)
	replace h_netinc=. if hhnetinc19_NR==1

	*~ other financial wealth 
	drop h_ofinwealth_lvl 
	sum ofinwealth_lvl, d
	gen h_ofinwealth_lvl=(ofinwealth_lvl>0)

	*~ net wealth 
	sum netwealth_Jan20, d
	gen h_netwealth=(netwealth_Jan20<r(p50))

	*~ recovery duration own net income  
	replace recov_owninc_duration=0 if recov_owninc_duration<0
	sum recov_owninc_duration  , d
	replace recov_owninc_duration=20 if never_owninc==1
	gen h_recovinc=(recov_owninc_duration>0)
	gen h_never_owninc = (never_owninc==1)

	*~ recovery duration own net wealth 
	sum recov_hhwealth_duration, d
	replace recov_hhwealth_duration=20 if never_ownwealth==1
	sum recov_hhwealth_duration, d
	gen h_recovwealth=(recov_hhwealth_duration>=r(p50))
	
	*~ demo
	gen h_male = male
	gen h_bach = atleast_bachelor 
	gen h_empl_ft =  empl_ft
	tab svydate, gen(svydate_)
			
global controls 		ln_hhnetinc  ///
						ln_ofinwealth_lvl ln_retirewealth_lvl  ///
						ln_realestate_lvl realestJan20_NR		///
						ln_debt_lvl  debtJan20_NR ///
						stockinvestor riskshare_finwealth_Jan201 stockexperience ///
						 age_25_34 age_35_44 age_45_54 age_55_64 age_65 male married separated_divorced widowed ///	
						highschool some_college_associate_degree atleast_bachelor  ///
						mainearner_alone z_constrained self_empl retired unempl empl_other ///
						republican other_party NR_party  ///
						z_decisionmaker ///
						midwest northeast south ///
						svydate_2 svydate_3 svydate_4 svydate_5 svydate_6 svydate_7 svydate_8 ///
						control_fincrisis control_dotcom control_black
									
									
* run OLS for wealth and IV on income			

foreach x in age netinc_alt ofinwealth_lvl 	never_owninc constrained retired {

	ivreg2 del_spend20_usd_tr02alt (delhhnetinc_exp20_USD_tr02alt=delhhnetinc_USD_tr02alt_qtr) ///
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt	///
									$controls	if h_`x'==0 ///
									, robust
									
				margins, dydx(delhhnetinc_exp20_USD_tr02alt) post
				est store `x'_inc_0					
									
									
		ivreg2 del_spend20_usd_tr02alt (delhhnetinc_exp20_USD_tr02alt=delhhnetinc_USD_tr02alt_qtr) ///
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt	///
									$controls	if h_`x'==1 ///
									, robust
	
				margins, dydx(delhhnetinc_exp20_USD_tr02alt) post
				est store `x'_inc_1
}	
	

	* first income splits:
		coefplot  	///
					(age_inc_0, label(Below med. age))		 ///
					(age_inc_1, label(Above med. age)),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.2)1, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "Below med. age") label(2 "Above med. age")) note("Age", pos(12) size(medium)) xlabel("") ///
						ytitle() ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90)  ///
						saving(Figures/coef1.gph, replace) 
					
		coefplot  	///
					(netinc_alt_inc_0, label(Below med. net income))		 ///
					(netinc_alt_inc_1, label(Above med. net income)),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.2)1, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "Below med. net income") label(2 "Above med. net income")) note("Net income", pos(12) size(medium)) xlabel("") ///
						ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90) ///
						saving(Figures/coef2.gph, replace)
						
		coefplot  	///
					(ofinwealth_lvl_inc_0, label(Zero other fin. wealth)  )		 ///
					(ofinwealth_lvl_inc_1, label(Positive other fin. wealth) ),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.2)1, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "Zero other fin. wealth") label(2 "Positive other fin. wealth")) note("Other financial wealth", pos(12) size(medium)) xlabel("") ///
						ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90) ///
						saving(Figures/coef3.gph, replace)
						
		coefplot  	///
					(never_owninc_inc_0, label(Income will recover)  )		 ///
					(never_owninc_inc_1, label(Income will never recover) ),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.5)2.5, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "Income will recover") label(2 "Income will never recover")) note("Income will never recover", pos(12) size(medium)) xlabel("") ///
						ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90) ///
						saving(Figures/coef4.gph, replace)				
		
		coefplot  	///
					(constrained_inc_0, label(Unconstrained)  )		 ///
					(constrained_inc_1, label(Constrained) ),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.2)1, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "Unconstrained") label(2 "Constrained")) note("Constrained", pos(12) size(medium)) xlabel("") ///
						ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90) ///
						saving(Figures/coef5.gph, replace)				
						
	
foreach x in   retired {
		ivreg2 del_spend20_usd_tr02alt (delhhnetinc_exp20_USD_tr02alt=delhhnetinc_USD_tr02alt_qtr) ///
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt	///
									$controls	if h_`x'==0 ///
									, robust
									
				margins, dydx(delhhnetinc_exp20_USD_tr02alt) post
				matrix r0 = r(table)
				est store `x'_inc_0					
									
		ivreg2 del_spend20_usd_tr02alt (delhhnetinc_exp20_USD_tr02alt=delhhnetinc_USD_tr02alt_qtr) ///
									delretir_USD_tr02alt ///
									delofin_USD_tr02alt	///
									$controls	if h_`x'==1 ///
									, robust
	
				margins, dydx(delhhnetinc_exp20_USD_tr02alt) post
				matrix r1 = r(table)
				matrix r_1 = r1[1,1]
				est store `x'_inc_1
}			
		
		coefplot  	///
					(retired_inc_0, label(All others)  )		 ///
					(matrix(r1), label(Retired) ),  recast(bar) barwidth(0.3)   ///
						vert ylabel(0(.2)1, nogrid) legend(size(medsmall)  pos(6) ring(1) cols(1) ///
						label(1 "All others") label(2 "Retired")) note("Retired", pos(12) size(medium)) xlabel("") ///
						ciopts(recast(rcap)) citop ysize(1) xsize(2) level(90) ///
						saving(Figures/coef6.gph, replace)				
				
		graph combine 	Figures/coef1.gph ///
						Figures/coef2.gph ///
						Figures/coef3.gph ///
						Figures/coef4.gph ///
						Figures/coef5.gph ///
						Figures/coef6.gph ///
						, cols(3) rows(2) ysize(2) xsize(3) ///
						l1title("Expected spending growth ($)", size(small)) ///
						iscale(0.6) imargin(large) 
					
		graph export Figures/FigureA6.pdf, as(pdf) fontface(cmr10) replace			
		graph export Figures/FigureA6.png, width(1600) replace	
	
	
	
forvalues x = 1/6 {
		capture erase Figures/coef`x'.gph
}
	
